#include<iostream>
#include<windows.h>
#include<stdlib.h>
using namespace std;
const int N = 10005;
float nums[N][N];
float v[N];
float sum[N];
void products1(int n) {
    for (int i = 1; i <= n; ++i) {
        sum[i] = 0.0;
        for (int j = 1; j <= n; ++j)
            sum[i] += nums[j][i] * v[j];
    }
}
void products2(int n) {
    for (int i = 1; i <= n; ++i)
        sum[i] = 0.0;
    for (int j = 1; j <= n; ++j)
        for (int i = 1; i <= n; ++i)
            sum[i] += nums[j][i] * v[j];
}
int main() {
    for (int i = 1; i < N; ++i)
        for (int j = 1; j < N; ++j)
            nums[i][j] = i + j;
    for (int i = 1; i < N; ++i)v[i] = i;
    long long head, tail, freq;
    QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
    int step = 10, cnt = 0;
    cout << "-------the first-----------" << endl;
    for (int n = 10; n <= 5000; n += step) {
        QueryPerformanceCounter((LARGE_INTEGER*)&head);
        do {
            products1(n);
            QueryPerformanceCounter((LARGE_INTEGER*)&tail);
            ++cnt;
        } while (tail - head < 20000);
        cout << "n=" << n << " " << (tail - head) * 1000 / freq << "ms   " << cnt <<" "<<sum[5]<< endl;
        cnt = 0;
        if (n == 100)step = 100;
        if (n == 1000)step = 1000;
    }
    step = 10, cnt = 0;
    for (int i = 1; i < N; ++i)sum[i] = 0;
    cout << "-------the second---------" << endl;
    for (int n = 10; n <= 5000; n += step) {
        QueryPerformanceCounter((LARGE_INTEGER*)&head);
        do {
            products2(n);
            QueryPerformanceCounter((LARGE_INTEGER*)&tail);
            ++cnt;
        } while (tail - head < 20000);
        cout << "n=" << n << " " << (tail - head) * 1000 / freq << "ms   " << cnt <<" "<<sum[5]<< endl;
        cnt = 0;
        if (n == 100)step = 100;
        if (n == 1000)step = 1000;
    }
}
